package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"video/internal/req"
	"video/internal/resp"
	"video/internal/service"
)

type UserHandler struct {
	UserService service.UserServiceImpl
	ReqLogin    req.ReqLogin
	LoginResp   resp.LoginResp
}

func NewUserHandler() *UserHandler {
	return &UserHandler{
		UserService: service.NewUserService(),
		ReqLogin:    req.ReqLogin{},
		LoginResp:   resp.LoginResp{},
	}
}

func (u UserHandler) Login(c *gin.Context) {

	if err := c.ShouldBind(&u.ReqLogin); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    10000,
			"message": "参数获取失败",
			"data":    nil,
		})
		return
	}

	login, err := u.UserService.Login(&u.ReqLogin)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    10000,
			"message": "登录失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "登录成功",
		"data":    login,
	})

}
